/*
 * @lc app=leetcode.cn id=203 lang=javascript
 *
 * [203] 移除链表元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */
var removeElements = function(head, val) {
   let res=new ListNode()
   res.next=head
   let now=res//一个空表头防止表头被删除的情况，如果不怎么必须等待表头被删除才能赋值给now引用
   while(now.next){
       if(now.next.val===val){
           now.next=now.next.next
       }else{
           now=now.next
       }
   }
   return res.next
};
// @lc code=end

